﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using SkinEngines.Win32;
using System.Drawing;

namespace SkinEngines.SkinForm
{
    /// <summary>
    /// Caption Button -- such as max,min,restore buttons
    /// </summary>
    [ToolboxItem(false)]
    [DesignTimeVisible(false)]
    public partial class CaptionButton : Component, INotifyPropertyChanged
    {
        #region Constructor
        /// <summary>
        /// Constructor
        /// </summary>
        public CaptionButton(HitTest hitTest)
        {
            InitializeComponent();

            // init data
            HitTest = hitTest;
            _hovered = false;
            _enabled = true;
            _pressed = false;
        }

        /// <summary>
        /// Constructor with container
        /// </summary>
        /// <param name="container"></param>
        public CaptionButton(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }
        #endregion

        #region Field
        /// <summary>
        /// the bounds of CaptionButton
        /// </summary>
        private Rectangle _bounds;

        /// <summary>
        /// is pressed
        /// </summary>
        private bool _pressed;

        /// <summary>
        /// is hovered
        /// </summary>
        private bool _hovered;

        /// <summary>
        /// is enabled
        /// </summary>
        private bool _enabled;
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the hit test result of this button.
        /// </summary>
        /// <value>The hit test result of this button.</value>
        public HitTest HitTest { get; private set; }

        /// <summary>
        /// Gets or sets the bounds where this button gets painted into.
        /// </summary>
        /// <value>The paint bounds.</value>
        public Rectangle Bounds
        {
            get
            {
                return _bounds;
            }
            set
            {
                if (value == _bounds) return;
                _bounds = value;
                PropertyChangedEventArgs e = new PropertyChangedEventArgs("Bounds");
                OnPropertyChanged(e);
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is hovered by the cursor.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is hovered; otherwise, <c>false</c>.
        /// </value>
        public bool Hovered
        {
            get
            {
                return _hovered;
            }
            set
            {
                if (value == _hovered) return;
                _hovered = value;
                PropertyChangedEventArgs e = new PropertyChangedEventArgs("Hovered");
                OnPropertyChanged(e);
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is pressed.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is pressed; otherwise, <c>false</c>.
        /// </value>
        public bool Pressed
        {
            get
            {
                return _pressed;
            }
            set
            {
                if (value == _pressed) return;
                _pressed = value;
                PropertyChangedEventArgs e = new PropertyChangedEventArgs("Pressed");
                OnPropertyChanged(e);
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="CaptionButton"/> is enabled.
        /// </summary>
        /// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value>
        [DefaultValue(false)]
        public bool Enabled
        {
            get
            {
                return _enabled;
            }
            set
            {
                if (value == _enabled) return;
                _enabled = value;
                PropertyChangedEventArgs e = new PropertyChangedEventArgs("Enabled");
                OnPropertyChanged(e);
            }
        }
        #endregion

        #region INotifyPropertyChanged Members

        /// <summary>
        /// Property Changed Event
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Raises the <see cref="PropertyChanged"/> event.
        /// </summary>
        /// <param name="e">The <see cref="System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param>
        private void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, e);
        }
        #endregion
    }
}
